package com.zsj.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import feign.Logger;
import org.springframework.web.client.RestTemplate;

//注意， 这里配置适合mybatis-plus 3.5.2版本
@Configuration
public class MyBatisConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

    @Bean
    Logger.Level level() {
        return Logger.Level.FULL;
    }

    @Bean
    @LoadBalanced //为RestTemplate添加负载均衡能力，
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    /**
     * 负载均衡  随机算法
     * @return
     */
    @Bean
    IRule myRule() {
        return new RandomRule();
    }

}
